<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://cdn.jsdelivr.net/npm/sortablejs@latest/Sortable.min.js"></script>
    <style>
        body {
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
        }

        #container {
            display: grid;
            grid-template-columns: repeat(9, 1fr);
            grid-template-rows: repeat(9, 40px);
            gap: 5px;
        }

        .cell {
            width: 100px;
            height: 40px;
            line-height: 40px;
            text-align: center;
            border: 1px solid #000;
            background-color: #fff;
            cursor: grab;
            user-select: none;
        }
    </style>
</head>
<body>

<div id="container"></div>

<script>
    // Function to generate a 9x9 multiplication table
    function generateTable() {
        const table = [];
        for (let i = 1; i <= 9; i++) {
            for (let j = 1; j <= 9; j++) {
                if (j >i) {
                    table.push('');}
                else
                    table.push(`${j} + ${i} = ${i + j}`);
            }
        }

        for (let i = table.length - 1; i > 0; i--) {
        const j = Math.floor(Math.random() * (i + 1));
        [table[i], table[j]] = [table[j], table[i]];
    }
        return table;
    }

    // Generate the initial multiplication table
    const initialTable = generateTable();

    // Create HTML elements for the initial table
    const container = document.getElementById("container");
    initialTable.forEach(value => {
        const cell = document.createElement("div");
        cell.className = "cell";
        cell.textContent = value;
        container.appendChild(cell);
    });

    // Make the container sortable
    const sortable = new Sortable(container, {
        animation: 150,
        draggable: '.cell',
        swap: true,
    });
</script>

</body>
</html>
